//***************************************************************************
//*
//*	File:			dswl_projects.cpp
//*	Description:	Wrapper for IProjects interface
//*
//***************************************************************************

//
//--------------------------------------------------------------- PRECOMPILED
//

#include "stdafx.h"

//
//--------------------------------------------------- DECLARATION DEPENDENCIES
//

//
//--------------------------------------------------------------- DECLARATION
//

#include "../Inc/dswl_projects.h"

//
//--------------------------------------------------- DEFINITION DEPENDENCIES
//

//
//-------------------------------------------------------------- PREPROCESSOR
//

#ifdef	_DEBUG
#define new DEBUG_NEW
#undef	THIS_FILE
static	char THIS_FILE[] = __FILE__;
#endif

//
//---------------------------------------------------------------- DEFINITION
//

/*
static void g_TestCasts()
{
	// test _safe_ conversions
	IProjects* pITest;
	CIProjects test	 ( pITest );
	CIProjects test2 = pITest ;

	test = test2;
	test = pITest;

	#ifdef _DSWL_SWITCH_USE_AUTOCAST

	// test _critical_ conversions
	pITest = test;
	CComPtr< IProjects > tmplTest = test;

	#endif
}
*/

//
//---------------------------------------------------------------------------------------------------
//*************************************     CON/DESTRUCTION     *************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																					  Constructor
//***************************************************************************************************
//**	@DOC		CONSTRUCTION
//**	@MFUNC		Default constructor
//**	@PARM		[in] A pointer to the interface to attach to
//**	@END
//***************************************************************************************************
//inline
CIProjects::CIProjects( IProjects* a_pIProjects /*= NULL*/ )
{
	this->m_pIProjects = a_pIProjects;
}

//***************************************************************************************************
//**																					   Destructor
//***************************************************************************************************
//**	@DOC		CONSTRUCTION
//**	@MFUNC		Default destructor
//**	@END
//***************************************************************************************************
//inline
CIProjects::~CIProjects()
{
	this->m_pIProjects = NULL;	// explicitly release the interface now
}

//
//---------------------------------------------------------------------------------------------------
//***************************************     PROPERTIES     ****************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																				   GetApplication
//***************************************************************************************************
//**	@DOC		PROPERTIES
//**	@MFUNC		Returns the application these projects belong to
//**	@RDESC		A pointer to the application's interface
//**	@END
//***************************************************************************************************
//inline
CIApplication CIProjects::GetApplication( void ) const 
{
	//
	//	CHECK VALIDITY
	//
	if ( FALSE == this->IsValid() )
	{
		return NULL;
	}

	//
	//	DELEGATE
	//
	IDispatch* pIDispatch = NULL;

	DSWL_VERIFY( this->m_pIProjects->get_Application( &pIDispatch ) );

	//
	//	QUERY INTERFACE
	//
	CComQIPtr< IApplication, &IID_IApplication > pIApplication ( pIDispatch );	

	//
	//	REPELASE DISPATCH INTERFACE
	//
	DSWL_RELEASE_EX( pIDispatch, CIProjects::GetApplication );

	//
	//	RETURN QUERIED INTERFACE
	//
	return pIApplication.p;												
}

//***************************************************************************************************
//**																						 GetCount 
//***************************************************************************************************
//**	@DOC		PROPERTIES
//**	@MFUNC		Returns the number of projects in this collection
//**	@RDESC		The number of projects in this collection
//**	@END
//***************************************************************************************************
//inline
long CIProjects::GetCount( void ) const 
{
	//
	//	CHECK VALIDITY
	//
	if ( FALSE == this->IsValid() )
	{
		return 0l;
	}

	//
	//	DELEGATE
	//
	long lCount = 0;

	DSWL_VERIFY( this->m_pIProjects->get_Count( &lCount ) );

	return lCount;
}

//
//---------------------------------------------------------------------------------------------------
//***************************************     INFORMATION     ***************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																						   IsNull
//***************************************************************************************************
//**	@DOC		INFORMATION
//**	@MFUNC		Determines whether the internal pointer is <t NULL>
//**	@RDESC		<t TRUE> if the internal pointer is <t NULL>, <t FALSE> otherwise.
//**	@END
//***************************************************************************************************
//inline
BOOL CIProjects::IsNull( void ) const
{
	return ( NULL == this->m_pIProjects.p );
}

//***************************************************************************************************
//**																						  IsValid
//***************************************************************************************************
//**	@DOC		INFORMATION
//**	@MFUNC		Determines whether the internal pointer differs from <t NULL>
//**	@RDESC		<t TRUE> if the internal pointer differs from <t NULL>, <t FALSE> otherwise.
//**	@END
//***************************************************************************************************
//inline
BOOL CIProjects::IsValid( void ) const
{
	return ( NULL != this->m_pIProjects.p );
}

//
//---------------------------------------------------------------------------------------------------
//***********************************     ELEMENT MANAGEMENT     ************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																					   		GetAt
//***************************************************************************************************
//**	@DOC		ELEMENT MANAGEMENT
//**	@MFUNC		Determines the item at specified 0-based index. 
//**	@PARM		[in] The 0-based index of the item to return
//**	@RDESC		A pointer to the project's generic interface
//**	@END
//***************************************************************************************************
//inline
CIGenericProject CIProjects::GetAt( long a_lIndex ) const 
{
	ASSERT( TRUE == this->IsValid() );

	return this->GetItem( a_lIndex + 1 );
}

//***************************************************************************************************
//**																					   	  GetItem
//***************************************************************************************************
//**	@DOC		ELEMENT MANAGEMENT
//**	@MFUNC		Determines the item at specified 1-based index. 
//**	@PARM		[in] The 1-based index of the item to return
//**	@RDESC		A pointer to the project's generic interface
//**	@END
//***************************************************************************************************
//inline
CIGenericProject CIProjects::GetItem( long a_lItem ) const 
{
	ASSERT( TRUE == this->IsValid() );

	IGenericProject*	pIGenericProject = NULL;
	CComVariant			varCount		( a_lItem );

	DSWL_VERIFY( this->m_pIProjects->Item( varCount, &pIGenericProject ) );

	CComPtr< IGenericProject > pITemp = pIGenericProject;

	DSWL_RELEASE_EX( pIGenericProject, CIProjects::GetItem );

	return pITemp;
}

//
//---------------------------------------------------------------------------------------------------
//****************************************     OPERATORS     ****************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																					  operator ==
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The text project to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CIProjects::operator == ( const CIProjects& a_Other ) const 
{
	return this->m_pIProjects == a_Other.m_pIProjects;
}

//***************************************************************************************************
//**																					  operator !=
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The text project to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CIProjects::operator != ( const CIProjects& a_Other ) const 
{
	return this->m_pIProjects != a_Other.m_pIProjects;
}

//***************************************************************************************************
//**																					  operator <=
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The text project to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CIProjects::operator <= ( const CIProjects& a_Other ) const 
{
	return this->m_pIProjects.p <= a_Other.m_pIProjects.p;
}

//***************************************************************************************************
//**																					  operator >=
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The text project to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CIProjects::operator >= ( const CIProjects& a_Other ) const 
{
	return this->m_pIProjects.p >= a_Other.m_pIProjects.p;
}

//***************************************************************************************************
//**																					   operator <
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The text project to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CIProjects::operator < ( const CIProjects& a_Other ) const 
{
	return this->m_pIProjects.p < a_Other.m_pIProjects.p;
}

//***************************************************************************************************
//**																					   operator >
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The text project to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CIProjects::operator > ( const CIProjects& a_Other ) const 
{
	return this->m_pIProjects.p > a_Other.m_pIProjects.p;
}

//***************************************************************************************************
//**																					   operator =
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Copy operator
//**	@PARM		[in] The text project to attach to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
CIProjects& CIProjects::operator = ( IProjects* a_pIOther ) 
{
	this->m_pIProjects = a_pIOther;

	return (*this);
}

//***************************************************************************************************
//**																					   operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Dereference operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
IProjects* CIProjects::operator * ( void ) 
{
	return this->m_pIProjects.p;
}

//***************************************************************************************************
//**																				 const operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Dereference operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
const IProjects* CIProjects::operator * ( void ) const 
{
	return this->m_pIProjects.p;
}

//***************************************************************************************************
//**																					  operator ->
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Member access operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
IProjects* CIProjects::operator -> ( void ) 
{
	return * (*this);
}

//***************************************************************************************************
//**																				const operator ->
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Member access operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
const IProjects* CIProjects::operator -> ( void ) const 
{
	return * (*this);
}

//***************************************************************************************************
//**																				const operator []
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Subscription operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
CIGenericProject CIProjects::operator [] ( int a_iIndex ) const 
{
	return this->GetAt( a_iIndex );
}

//---------------------------------------------------------------------------------------------------
//***************************************************************************************************
//---------------------------------------------------------------------------------------------------

#ifdef _DSWL_SWITCH_USE_AUTOCAST
#ifdef _DSWL_SWITCH_USE_UNSAFE_AUTOCAST

//***************************************************************************************************
//**																				 const operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		TypeCast operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
CIProjects::operator IProjects* ( void ) const 
{
	return this->m_pIProjects.p;
}

#else

//***************************************************************************************************
//**																					   operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		TypeCast operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
CIProjects::operator IProjects* ( void ) 
{
	return this->m_pIProjects.p;
}

//***************************************************************************************************
//**																				 const operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		TypeCast operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
CIProjects::operator const IProjects* ( void ) const 
{
	return this->m_pIProjects.p;
}

#endif
#endif


